package com.game.server.message.proto.execute;

import com.comm.ISession;
import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYtopUpIntegralReq;
import com.game.server.message.proto.out.XYtopUpIntegralRsp;

public class XYtopUpIntegralReq extends AbstractXYtopUpIntegralReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null && client.checkClick(msgcode)) {
            XYtopUpIntegralRsp rsp = new XYtopUpIntegralRsp();
            rsp.setIsok(1);
            rsp.setValue(this.value);
            rsp.setType(this.type);
            XyClubInfo xyClubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (xyClubInfo != null) {
                XyClubMemberInfo memberInfo = xyClubInfo.getPlayer().get(client.getUserId());
                if (memberInfo != null && (memberInfo.getIsManager() == 1 || memberInfo.getIsManager() == 2)) {
                    if (this.type == 1) {
                        int isok = xyClubInfo.updateJiJin(memberInfo.getUid(), 0, value, 1);
                        rsp.setIsok(isok);
                    }
                    if (this.type == 2) {
                        rsp.setUid(this.uid);
                        XyClubMemberInfo toMemberInfo = xyClubInfo.getPlayer().get(this.uid);
                        if (toMemberInfo!=null){
                            int isok = xyClubInfo.updateJiJin(memberInfo.getUid(), toMemberInfo.getUid(), value, 2);
                            rsp.setIsok(isok);
                        }
                    }
                }
            }

            client.Send(rsp);
        }
    }

}
